home *** CD-ROM | disk | FTP | other *** search
/ Gigarom 4 / Mac Giga-ROM 4.0 - 1993.toast / FILES / DEV / I-Z / Progress Tube Unit.cpt / Progress Tube Unit Folder / ProgressTube.c < prev    next >
Text File  |  1992-12-31  |  4KB  |  139 lines

  1. /* (c) 1992-1993 Christopher Kline    Chameleon Software                                     */
  2. /* This is declared to be "No Good Reason To Be Anything Other Than FreeWare"             */
  3. /* Anyone may use it without any compensation to me, as long as I receive some Email    */
  4. /*    letting me know that you're using it (what a rush!). Hope you find it useful         */
  5. /* these routines need MacTraps, MacTraps2, and ANSI libraries to function                 */
  6.  
  7. #include "ProgressTube.h"
  8.  
  9. Rect    defaultRect    =    {120, 70, 240, 440};
  10.  
  11. /*====================================================================================*/
  12. OSErr    NewTube(TubeType *theTube, Str255 theTitle)
  13. {
  14.     Str255    titleChoice    =    kDefaultTubeTitle;
  15.     
  16.     #define    kAllocateMemoryForMe        NULL
  17.     #define    kShowTheProgressTubeNow        TRUE
  18.     #define    kNoCloseBox                    FALSE
  19.     #define    kInFront                    (WindowPtr) -1
  20.     
  21.     if (theTitle != NULL) 
  22.         strcpy(titleChoice, theTitle); /* strcpy(destination, source)  */
  23.     
  24.     theTube->tubeWindow =
  25.         NewWindow ( kAllocateMemoryForMe, &defaultRect,titleChoice, kShowTheProgressTubeNow,
  26.                     kDefaultTubeType, kInFront, kNoCloseBox, (long)"TUBE" );
  27.  
  28.     SetRect(     
  29.                 &(theTube->tubeOutlineRect), 
  30.                 ((*theTube).tubeWindow)->portRect.left        +    20-1,
  31.                 ((*theTube).tubeWindow)->portRect.top        +    55-1,
  32.                 ((*theTube).tubeWindow)->portRect.right        -    20+1,
  33.                 ((*theTube).tubeWindow)->portRect.bottom    -    50+1
  34.             
  35.             );  /* form: SetRect( &rect, left, top, right, bottom) */
  36.                     
  37.     if (theTube->tubeWindow != NULL) 
  38.         return( noErr );
  39.     else
  40.         return( memFullErr);
  41. }
  42. /*====================================================================================*/
  43. FillTube(TubeType theTube, Str255 *theString, float *thePercentage)
  44. {
  45.     Rect             fillRect;    
  46.     GrafPtr            savedPort;    
  47.     Str255            messageChoice    =    kDefaultTubeMessage;
  48.  
  49.     if (*theString != NULL) 
  50.         strcpy(messageChoice, *theString); /* strcpy(destination, source)  */
  51.                 
  52.  
  53.     GetPort( &savedPort );            /* remember the previous grafport      */
  54.     SetPort(theTube.tubeWindow);
  55.     
  56.     ForeColor(blackColor);
  57.     FrameRect( &theTube.tubeOutlineRect ); /*outline the fill bar */
  58.  
  59.     TextFont( kDefaultFontNum );
  60.     TextSize( kDefaultFontSize );
  61.     TextMode( srcCopy );
  62.     MoveTo( theTube.tubeWindow->portRect.left +    20, theTube.tubeWindow->portRect.top + 35 );    
  63.     DrawString( messageChoice );
  64.     DrawString( "\p                                                            " );
  65.  
  66.     ForeColor(kDefaultTubeColor);
  67.     SetRect(
  68.                 &fillRect, 
  69.                 theTube.tubeWindow->portRect.left        +    20,
  70.                 theTube.tubeWindow->portRect.top        +    55,
  71.                 (theTube.tubeWindow->portRect.right        -    20) * (*thePercentage),
  72.                 theTube.tubeWindow->portRect.bottom        -    50
  73.             
  74.             ); /* form: SetRect( &rect, left, top, right, bottom) */
  75.  
  76.     if (*thePercentage <= 1 ) /* don't overflow the fill tube! */
  77.         PaintRect( &fillRect );
  78.     
  79.     SetPort( savedPort );            /* restore the previous grafport */
  80. }
  81. /*====================================================================================*/
  82. ResetTube(TubeType theTube)
  83. {
  84.     GrafPtr            savedPort;                
  85.  
  86.     GetPort( &savedPort );            /* remember the previous grafport      */    
  87.     SetPort(theTube.tubeWindow);
  88.     EraseRect( &theTube.tubeOutlineRect );
  89.     SetPort( savedPort );            /* restore the previous grafport */
  90. }
  91. /*====================================================================================*/
  92. DisposeTube(TubeType    theTube)
  93. {
  94.     if     (theTube.tubeWindow != NULL)
  95.         DisposeWindow(theTube.tubeWindow);
  96. }
  97. /*====================================================================================*/
  98. CenterTube(TubeType    theTube)
  99. {
  100.     Rect    r;
  101.     int        width,
  102.             height,
  103.             sWidth,
  104.             sHeight,
  105.             h,
  106.             v;
  107.     
  108.     r        =    theTube.tubeWindow->portRect;
  109.     width    =    r.right        -    r.left;
  110.     height    =    r.bottom    -    r.top;    
  111.     
  112.     sWidth    =    screenBits.bounds.right        -    screenBits.bounds.left;    
  113.     sHeight    =    screenBits.bounds.bottom    -    screenBits.bounds.top;    
  114.     
  115.     h        =    screenBits.bounds.left        +    ( (sWidth  - width)  / 2 );
  116.     v        =    screenBits.bounds.top        +    ( (sHeight - height) / 2 );
  117.             
  118.     MoveWindow( theTube.tubeWindow, h, v, FALSE );        
  119. }
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.